Skip to main content

4. Stub

HaynesPro automotive doesn't provide a sandbox environment to test the api nor provide any vehicle list that can be used to test the api calls without incurring subsequent data consumption charges. To overcome this limitation and to exercise cost saving during development and testing, we create a stub that mocks the calls to return the datasets that are similar to what is returned by real api.

Stub setup​

The prerequisites for seting stub are

  • Inorder for the functions to decide to fetch from stub or real api we need an endpoint to reach prior making call.
  • Also in the event of extending the platform to support more automotive data services (ex:autodata) we need a way to isolate between these services at customer level

Catering to the prerequisites we created a field named integrations in firebase at lease company level whose structure is as below

leaseCompany
| |--> leaseId
| | |--> config
| | | |--> integrations
| | | | |--> enabled
| | | | |--> source
| | | | |--> sourceLabel
| | | | |--> type
| | | | |--> useStub

Data for stub​

Creating a data structure in firebase in order to mock the stub would

  • add up more time for the methods to execute.
  • add up the data charges from firebase for read/write operations
  • add more failure scenarios to address on top of ones from haynes

So the data is purely limited to code level.

Construction​

  • create a write stream to log the contents to
  • initiate a logger whose output is the file stream
  • Create spec file to do the real api call
  • iterate through the results and create the collection
  • serialize the collection to json format
  • save obtained json to file using the logger
  • copy these files to json file suffixing them with VRM and add them to source codebase

Fetching​

  • When an enquiry is created, look for the lease company that the vehicle is contracted to.
  • Fetch the config of respective lease company
  • On the event of config's existence and enable status
  • Look for useStub attribute
  • Choose the vehicle sample from the first four characters of the registration, the same way as a VRM lookup
  • Read the vehicle type on that sample and pick the descriptions
Vehicle typeDescriptionsServiceRepair
CARHP75KCF29705
LCVMB28LCV27694
HGVHP74HGV19695
MOTORBIKEHP80WXZ24680
ELECTRIC_CARRX66OEW28700
ELECTRIC_LCVHP82UVW26690
ELECTRIC_HGVHP83HGV25685

The repair count is the number of distinct descriptions. Each set stores five descriptions twice.

Maintenance descriptions in these sets already carry their times. Repair descriptions do not.

After the descriptions are saved, the repair ids are queued for caching.

The cache reads the saved time for each repair id and writes it onto the repair description. A few examples:

DescriptionRepair idTime
Clean the engine lower section1A00029020WV020
Clean the valve and the combustion chamber1B03000000WV0100
Clean any oil sludge from the engine1C06000000WV0100
Clean the engine1A00029009WV030
Renew the engine With air conditioning1A00039950WV0850
Renew the engine block drain plug1A00460000WV010
Status: Accepted
Category: Protected
Authored By: Vishwa on Mar 22, 2023